package com.kai.steering.data.service.entity.po;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.IdType;

import java.util.Date;

import com.baomidou.mybatisplus.annotation.TableId;

import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.TableName;
import com.kai.steering.data.service.entity.domainObject.KnowledgeDO;
import com.kai.steering.data.service.entity.domainObject.WarehouseDO;
import com.kai.steering.data.service.entity.dto.WarehouseQueryDTO;
import lombok.*;

import java.io.Serializable;
import java.util.stream.Collectors;

/**
 * <pre>
 * 仓库
 * </pre>
 *
 * @author kai
 * @since 2022-02-23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
@EqualsAndHashCode(callSuper = false)
@TableName(value = "warehouse")

public class Warehouse implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 仓库id
     */
    @TableId(value = "warehouse_id", type = IdType.ASSIGN_UUID)

    private String warehouseId;


    /**
     * 仓库名
     */

    private String warehouseName;


    /**
     * 上级仓库
     */

    private String warehouseSuperior;


    /**
     * 仓库信息
     */

    private String warehouseInformation;


    /**
     * 创建时间
     */

    private Date creationDatetime;


    /**
     * 管理员id或者用户id
     */

    private String founder;


    /**
     * 知识点分类
     */

    private String knowledgeId;


    /**
     * 级别
     */

    private Integer level;


    /**
     * 存在0删除1
     */

    private Integer usable;


    /**
     * 删除日期
     */

    private Date deleteDatetime;


    public Warehouse(WarehouseQueryDTO warehouseQueryDTO) {
        BeanUtil.copyProperties(warehouseQueryDTO, this);
    }

    public Warehouse(WarehouseDO warehouseDO) {
        this.warehouseId=warehouseDO.getWarehouseId();
        this.warehouseName=warehouseDO.getWarehouseName();
        this.warehouseSuperior=warehouseDO.getWarehouseSuperior();
        this.warehouseInformation=warehouseDO.getWarehouseInformation();
        this.creationDatetime=warehouseDO.getCreationDatetime();
        this.founder=warehouseDO.getFounder();
        if (warehouseDO.getKnowledges()!=null) {
            this.knowledgeId= warehouseDO.getKnowledges().stream().map(KnowledgeDO::getKnowledgeId).collect(Collectors.joining(","));
        }
        this.level=warehouseDO.getLevel();
        this.usable=warehouseDO.getUsable();
        this.deleteDatetime=warehouseDO.getDeleteDatetime();
    }
}
